package com.plian.system.controller.cqzc.bondsapply;

import com.plian.Tools.base.BaseController;
import com.plian.Tools.pagedata.PageData;
import com.plian.system.annotation.LogOperation;
import com.plian.system.model.ListResult;
import com.plian.system.model.ObjResult;
import com.plian.system.service.cqzc.bondsapply.BondsApplyService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletResponse;
import java.io.OutputStream;
import java.util.List;

/**
 * 说明：发债申请
 * 创建时间:2020-04-27 14:21:49
 */
@RestController
@RequestMapping(value = "api/bonds_apply")
public class BondsApplyController extends BaseController {

    @Autowired
    private BondsApplyService bondsapplyService;


    /**
     * 保存
     *
     * @param
     * @throws Exception
     */
    @PostMapping(value = "/save")
    @LogOperation("发债申请-保存")
    public ObjResult save(@RequestBody PageData pd) throws Exception {
        return bondsapplyService.save(pd);
    }

    /**
     * 修改
     *
     * @param
     * @throws Exception
     */
    @PostMapping(value = "/edit")
    @LogOperation("发债申请-编辑")
    public ObjResult edit(@RequestBody PageData pd) throws Exception {
        return bondsapplyService.edit(pd);
    }

    /**
     * 根据id查询
     *
     * @param pd
     * @return
     * @throws Exception
     */
    @PostMapping(value = "/findbyid")
    public ObjResult findbyid(@RequestBody PageData pd) throws Exception {
        return bondsapplyService.findbyid(pd);
    }

    /**
     * 根据集合删除数据
     *
     * @param pd
     * @return
     * @throws Exception
     */
    @PostMapping(value = "/del_ids")
    @LogOperation("发债申请-删除")
    public ObjResult delids(@RequestBody PageData pd) throws Exception {
        return bondsapplyService.del_ids((List<String>) pd.get("ids"));
    }

    /**
     * 查询列表
     *
     * @return
     * @throws Exception
     */
    @PostMapping(value = "/list")
    public ListResult listpage(@RequestBody PageData pd) throws Exception {
        return bondsapplyService.listPage(pd);
    }

    @PostMapping(value = "/reportList")
    public ListResult reportList(@RequestBody PageData pd) throws Exception {
        return bondsapplyService.reportList(pd);
    }


    /**
     * 查询未使用现有批文的发债申请
     * @return
     * @throws Exception
     */
    @PostMapping(value = "/unusedList")
    public ListResult unusedList(@RequestBody PageData pd) throws Exception {
        pd.put("unused","1");
        return bondsapplyService.listPage(pd);
    }


    /**
     * 有效期内的申请单
     *
     * @param pd
     * @return
     * @throws Exception
     */
    @PostMapping(value = "/periodOfValidityList")
    @LogOperation("发债申请-查询有效期内申请单")
    public ListResult periodOfValidityList(@RequestBody PageData pd) throws Exception {
        return bondsapplyService.periodOfValidityList(pd);
    }

    /**
     * 出资企业债券发行情况报告表
     *
     * @param pd
     * @return
     * @throws Exception
     */
    @PostMapping(value = "/report")
    public ListResult report(@RequestBody PageData pd) throws Exception {
        return bondsapplyService.report(pd);
    }

    /**
     * 出资企业债券发行情况报告表导出
     *
     * @param pd
     * @return
     * @throws Exception
     */
    @RequestMapping(value = "/reportExcel")
    @LogOperation("发债申请-导出")
    public void reportExcel(@RequestBody PageData pd, HttpServletResponse response, OutputStream os) throws Exception {
        bondsapplyService.reportExcel(pd, response, os);
    }
}